package com.apes.hr.base.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.api.SpringManager;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.hr.recruit.model.RecruitChannel;
import com.apes.hr.recruit.model.RecruitOrder;
import com.apes.scm.masterdata.area.model.Area;
import com.apes.scm.masterdata.area.model.Country;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.enumeration.repository.EnumerationRepository;
import com.apes.scm.masterdata.frame.model.Branch;
import com.apes.scm.masterdata.party.model.Party;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apestech.framework.util.StringUtil;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.persistence.*;
import java.util.*;

/**
 * 功能：人员档案
 * @author HuJianlin
 * @create 2018-04-25 15:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = Employee.CONST_TABLE_NAME)
public class Employee extends Model {
    public static final String CONST_TABLE_NAME = "hr_Employee";

    @Id
    @Column(name = "id", nullable = false, length = 120)
    //@ApesGenerator(code = CONST_TABLE_NAME, name = "人员编码", padding = 8)
    @Comment("人员编码")
    private String id; //人员编码

    @Name
    @Column(name = "name", nullable = false, length = 200)
    @Comment("人员名称")
    private String name; //人员名称

    @Column(name = "state", length = 10)
    @Comment("状态")
    private String state; //状态： ('sent', '创建'), ('approve', '审核')

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "party_id", referencedColumnName = "id")
    @Comment("当事人编码")
    private Party party; //当事人编码

    @Column(name = "mobile_number", length = 16,unique = true)
    @Comment("手机号")
    private String mobileNumber; //手机号

    @Column(name = "office_phone", length = 16)
    @Comment("办公电话")
    private String officePhone; //办公电话

    @Column(name = "telephone", length = 16)
    @Comment("固定电话")
    private String telephone; //固定电话

    @Column(name = "mail_address")
    @Comment("邮寄地址")
    private String mailAddress; //邮寄地址

    @Column(name = "postal_address")
    @Comment("通讯地址")
    private String postalAddress;  //通讯地址

    @Column(name = "id_card_address")
    @Comment("身份证地址")
    private String idCardAddress;  //身份证地址

    @Column(name = "postal_code", length = 8)
    @Comment("值班岗位")
    private String postalCode; //邮政编码（改成值班岗位）

    @Column(name = "qq", length = 16)
    @Comment("qq")
    private String qqNumber; //qqqq

    @Column(name = "email", length = 32)
    @Comment("email")
    private String email; //email

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "sex", referencedColumnName = "id")
    @Comment("性别")
    private Enumeration sex; //性别

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "birthday")
    @Comment("生日")
    private Date birthday; //生日

    @Column(name = "id_card", length = 32,unique = true)
    @Comment("身份证号")
    private String idCard;  //身份证号

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "id_card_term")
    @Comment("身份证到期时间")
    private Date idCardTerm;//身份证到期时间

    @Column(name = "weight", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("体重")
    private double weight; //体重

    @Column(name = "height", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("身高")
    private double height; //身高

    @Column(name = "bank", length = 32)
    @Comment("工资卡开户行")
    private String bank; //工资卡开户行

    @Column(name = "bank_account", length = 32)
    @Comment("工资卡帐号")
    private String bankAccount; //工资卡帐号

    @Column(name = "social_security_cards", length = 32)
    @Comment("社保卡号")
    private String socialSecurityCards; //社保卡号

    @Column(name = "native_place", length = 40)
    @Comment("籍贯")
    private String nativePlace; //籍贯

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "census_reg_nature", referencedColumnName = "id")
    @Comment("户口性质")
    private Enumeration censusRegNature; //户口性质

    //户籍地址
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reg_country_id", referencedColumnName = "id")
    @Comment("户籍地址.国家")
    private Country regCountry; //户籍地址.国家

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reg_province_id", referencedColumnName = "id")
    @Comment("户籍地址.省份")
    private Area regProvince; //户籍地址.省份

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reg_city_id", referencedColumnName = "id")
    @Comment("户籍地址.城市")
    private Area regCity; //户籍地址.城市

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reg_county_id", referencedColumnName = "id")
    @Comment("户籍地址.区县")
    private Area regCounty; //户籍地址.区县

    @Column(name = "reg_address", length = 500)
    @Comment("户籍地址.地址")
    private String regAddress; //户籍地址.地址

    //居住地址
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "living_country_id", referencedColumnName = "id")
    @Comment("居住地址.国家")
    private Country livingCountry; //居住地址.国家

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "living_province", referencedColumnName = "id")
    @Comment("居住地址.省份")
    private Area livingProvince; //居住地址.省份

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "living_city_id", referencedColumnName = "id")
    @Comment("居住地址.城市")
    private Area livingCity; //居住地址.城市

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "living_county_id", referencedColumnName = "id")
    @Comment("居住地址.区县")
    private Area livingCounty; //居住地址.区县

    @Column(name = "living_address", length = 500)
    @Comment("居住地址.地址")
    private String livingAddress; //居住地址.地址

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "nation", referencedColumnName = "id")
    @Comment("民族")
    private Enumeration nation; //民族

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "blood_type", referencedColumnName = "id")
    @Comment("血型")
    private Enumeration bloodType; //血型

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "political_visage", referencedColumnName = "id")
    @Comment("政治面貌")
    private Enumeration politicalVisage; //政治面貌

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "marital_state", referencedColumnName = "id")
    @Comment("婚姻状况")
    private Enumeration maritalState; //婚姻状况

//    @ManyToOne(fetch = FetchType.LAZY)
//    @JoinColumn(name = "unacceptable_id", referencedColumnName = "id")
//    private Enumeration unacceptable; //不能接受的企业行为

    @Column(name = "hope_work_place", length = 100)
    @Comment("期望工作地点")
    private String hopeWorkPlace; //期望工作地点

    @Column(name = "the_only_child", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否独生子女")
    private boolean theOnlyChild = true; //是否独生子女

    @Column(name = "contact", length = 64)
    @Comment("紧急联系人")
    private String contact;  //紧急联系人

    @Column(name = "contact_phone", length = 64)
    @Comment("紧急联系人电话")
    private String contactPhone;  //紧急联系人电话

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "mandarin_Level", referencedColumnName = "id")
    @Comment("普通话水平")
    private Enumeration mandarinLevel;  //普通话水平(skillProficiency)

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "local_dialect_Level", referencedColumnName = "id")
    @Comment("本地方言水平")
    private Enumeration localDialectLevel;  //本地方言水平(skillProficiency)

    @Column(name = "typing_speed", nullable = false, columnDefinition = "number(8,0) default 0")
    @Comment("打字速度")
    private int typingSpeed = 0;    //打字速度

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ime", referencedColumnName = "id")
    @Comment("输入法")
    private Enumeration ime;    //输入法

    //---------------------------------------------------------
    // @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @Comment("所属公司")
    private PartyRole company; //所属公司

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "work_branch_id", referencedColumnName = "id")
    @Comment("工作部门")
    private Branch workBranch; //工作部门

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "entry_date")
    @Comment("入职日期")
    private Date entryDate;  //入职日期

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "post_id", referencedColumnName = "id")
    @Comment("岗位")
    private WorkPost post; //岗位

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "job_id", referencedColumnName = "id")
    @Comment("职位")
    private Job job; //职位


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "rank_id", referencedColumnName = "id")
    @Comment("职级")
    private Rank rank; //职级

    @Column(name = "post_describe",length = 120)
    @Comment("岗位描述")
    private String postDescribe;//岗位描述

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "employee_state_id", referencedColumnName = "id")
    @Comment("员工状态")
    private Enumeration employeeState; //员工状态(employeeState)从申请面试开始  同旧框架 :(000088:在职;000089:已离职;000417:待入职)

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "on_duty_state", referencedColumnName = "id")
    @Comment("在职状态")
    private Enumeration onDutyState; //在职状态(onDutyState)

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "quit_state_id", referencedColumnName = "id")
    @Comment("离职状态")
    private Enumeration quitState; //离职状态(quitState) 000412	预离职；000413	正常离职；000414	未交接离职

    @Column(name = "staff_share",  nullable = false, columnDefinition = "number(16,4) default 0")
    @Comment("份数")
    private double staffShare = 0; //份数 份额

    @Column(name = "driver",  nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否准驾人员")
    private boolean driver = false; // 是否准驾人员(0:否;1:是)改成 是否上传驾驶证 正面

    @Column(name = "echelon", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否梯队")
    private boolean echelon = false;  //是否梯队(0:否;1:是)\

    @Column(name = "skilled", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否熟练驾驶")
    private boolean skilled = false;//是否熟练驾驶（0：否；1：是）

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "employee_ivy", referencedColumnName = "id")
    @Comment("长青藤届别")
    private Enumeration employeeIvy;//长青藤届别

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "train_route", referencedColumnName = "id")
    @Comment("培养路线")
    private Enumeration trainRoute;//培养路线

    //---------------------------------------------------------
    @Column(name = "source_type", length = 16)
    @Comment("来源单据类型")
    private String sourceType;  //来源单据类型

    @Column(name = "source_number", length = 16)
    @Comment("来源单号")
    private String sourceNumber;  //来源单号

    @Column(name = "origin", length = 32)
    @Comment("外部ID")
    private String origin;  //外部ID 操作员账号

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效")
    private boolean valid = true; //有效

    @OneToMany(mappedBy = "employee", cascade=CascadeType.ALL, orphanRemoval = true)
    @Comment("家庭成员")
    private Set<EmployeeFamily> employeeFamilies = new HashSet(); //家庭成员

    public Set<EmployeeFamily> getEmployeeFamilies() {
        if (employeeFamilies == null) return null;
        for (EmployeeFamily employeeFamily : employeeFamilies) {
            employeeFamily.setEmployee(this);
        }
        return employeeFamilies;
    }
    public void setEmployeeFamilies(Set<EmployeeFamily> employeeFamilies) {
        if (employeeFamilies == null) employeeFamilies = new HashSet<>();
        this.employeeFamilies.clear();
        this.employeeFamilies.addAll(employeeFamilies);
    }

    @OneToMany(mappedBy = "employee", cascade=CascadeType.ALL, orphanRemoval = true)
    @Comment("教育背景")
    private Set<EmployeeEducation> employeeEducations = new HashSet(); //教育背景

    public Set<EmployeeEducation> getEmployeeEducations() {
        if (employeeEducations == null) return null;
        for (EmployeeEducation employeeEducation : employeeEducations) {
            employeeEducation.setEmployee(this);
        }
        return employeeEducations;
    }
    public void setEmployeeEducations(Set<EmployeeEducation> employeeEducations) {
        if (employeeEducations == null) employeeEducations = new HashSet<>();
        this.employeeEducations.clear();
        this.employeeEducations.addAll(employeeEducations);
    }

    @OneToMany(mappedBy = "employee", cascade=CascadeType.ALL, orphanRemoval = true)
    @Comment("工作经历")
    private Set<EmployeeWorkHistory> employeeWorkHistories = new HashSet(); //工作经历

    public Set<EmployeeWorkHistory> getEmployeeWorkHistories() {
        if (employeeWorkHistories == null) return null;
        for (EmployeeWorkHistory employeeWorkHistory : employeeWorkHistories) {
            employeeWorkHistory.setEmployee(this);
        }
        return employeeWorkHistories;
    }
    public void setEmployeeWorkHistories(Set<EmployeeWorkHistory> employeeWorkHistories) {
        if (employeeWorkHistories == null) employeeWorkHistories = new HashSet<>();
        this.employeeWorkHistories.clear();
        this.employeeWorkHistories.addAll(employeeWorkHistories);
    }

    // 技能 证书
    @OneToMany(mappedBy="employee", cascade=CascadeType.ALL, orphanRemoval = true)
    @Comment("技能 证书")
    private Set<EmployeeSkillCertificate> employeeSkillCertificates = new HashSet<>();
    public Set<EmployeeSkillCertificate> getEmployeeSkillCertificates() {
        if (employeeSkillCertificates == null) return null;
        for (EmployeeSkillCertificate employeeSkillCertificate : employeeSkillCertificates) {
            employeeSkillCertificate.setEmployee(this);
        }
        return employeeSkillCertificates;
    }
    public void setEmployeeSkillCertificates(Set<EmployeeSkillCertificate> employeeSkillCertificates) {
        if (employeeSkillCertificates == null) employeeSkillCertificates = new HashSet<>();
        this.employeeSkillCertificates.clear();
        this.employeeSkillCertificates.addAll(employeeSkillCertificates);
    }

     //调动记录
    @OneToMany(mappedBy="employee", cascade=CascadeType.ALL, orphanRemoval = true)
    @Comment("调动记录")
    private Set<TransferRecord> transferRecords = new HashSet<>();
    public Set<TransferRecord> getTransferRecords() {
        if (transferRecords == null) return null;
        for (TransferRecord transferRecord : transferRecords) {
            transferRecord.setEmployee(this);
        }
        return transferRecords;
    }
    public void setTransferRecords(Set<TransferRecord> transferRecords) {
        if (transferRecords == null) transferRecords = new HashSet<>();
        this.transferRecords.clear();
        this.transferRecords.addAll(transferRecords);
    }


    @ManyToOne(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
    @JoinColumn(name = "recruit_order_id", referencedColumnName = "id")
    private RecruitOrder recruitOrder;//招聘单缺岗所属人


    @Column(name = "photo", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传照片")
    private boolean photo = false; //是否上传照片

    @Column(name = "diploma", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传毕业证")
    private boolean diploma = false; //是否上传毕业证

    @Column(name = "medical", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传体检报告")
    private boolean medical = false; //是否上传体检报告

    @Column(name = "id_card_photo", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传身份证正面")
    private boolean idCardPhoto = false; //是否上传身份证正面

    @Column(name = "id_card_photo_r", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传身份证反面")
    private boolean idCardPhotoR = false; //是否上传身份证反面

    @Column(name = "bank_card_photo", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传银行卡正面")
    private boolean bankCardPhoto = false; //是否上传银行卡正面

    @Column(name = "bank_card_photo_r", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传银行卡反面")
    private boolean bankCardPhotosR = false; //是否上传银行卡反面

    @Column(name = "driver_r", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传驾驶证反面")
    private boolean driverR = false; //是否上传驾驶证反面

    @Column(name = "job_photo", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传职业资格证明")
    private boolean jobPhoto = false; //是否上传职业资格证明

    @Column(name = "quit_photo", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传离职资格证明")
    private boolean quitPhoto = false; //是否上传离职资格证明

    @Column(name = "one_inch_photo", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传白底一寸照片")
    private boolean oneInchPhoto = false; //是否上传白底一寸照片

    @Column(name = "veteran_photo", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传退伍军人证")
    private boolean veteranPhoto = false; //是否上传退伍军人证

    @Column(name = "handicapped_photo", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传残疾人证")
    private boolean handicappedPhoto = false; //是否上传残疾人证

    @Column(name = "driver_license", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否上传驾驶证")
    private boolean driverLicense = false; //是否上传驾驶证 改 是否在公司备案许可驾驶

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "driver_term")
    @Comment("驾驶证到期时间")
    private Date driverTerm;//驾驶证到期时间


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "test_examiner_id", referencedColumnName = "id")
    @Comment("人资面试官")
    private PartyRole testExaminer;  //人资面试官

    @Column(name="teacher")
    @Comment("带教老师")
    private String teacher;//带教老师

    @Column(name="english_level")
    @Comment("英语水平")
    private String englishLevel;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "driver_license_type", referencedColumnName = "id")
    @Comment("驾照类型")
    private Enumeration driverLicenseType;//驾照类型

    @Column(name = "dormitory")
    @Comment("入住宿舍")
    private String dormitory;//入住宿舍

    @Column(name = "name_before")
    @Comment("曾用名")
    private String nameBefore;//曾用名

    @Column(name = "passports")
    @Comment("护照、港澳通行证号")
    private String passports;//护照、港澳通行证号

    @Column(name="drive_proficiency")
    @Comment("驾驶熟练程度")
    private  String driveProficiency; //驾驶熟练程度

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "disability_level", referencedColumnName = "id")
    @Comment("残疾人等级")
    private Enumeration disabilityLevel; //残疾人等级

    @Column(name="disability_number")
    @Comment("残疾人证号")
    private String disabilityNumber; //残疾人证号

    @Column(name="different_works",length = 4000)
    @Comment("可接受的异地工作地点")
    private String differentWorks;  //可接受的异地工作地点

    public void setDifferentWorks(String differentWorks) {
    }
    public void DifferentWorksToApp(String differentWorks) {
        this.differentWorks = differentWorks;
    }

    @Transient
    private Set<Enumeration> differentWorksSet;

    public Set<Enumeration> getDifferentWorksSet() {
        if (isWrite() || isLoad()) {
            differentWorksSet = getReason(this.differentWorks);
        }
        return differentWorksSet;
    }
    public void setDifferentWorksSet(Set<Enumeration> differentWorksSet) {
        this.differentWorksSet = differentWorksSet;
        if (!isWrite()) {
            this.differentWorks = toConvertReason(this.differentWorksSet);
        }
    }

    @Column(name="social_security_place")
    @Comment("社保购买地")
    private String socialSecurityPlace; //社保购买地

    @Column(name="social_security_cards_ofdate")
    @Comment("社保卡发放日期")
    private Date  socialSecurityCardsOfDate;//社保卡发放日期


    @Column(name = "office", length = 4000)
    @Comment("办公软件")
    private String office;  //办公软件

    public void setOffice(String office) {
    }

    @Transient
    private Set<Enumeration> officeSet;

    public Set<Enumeration> getofficeSet() {
        if (isWrite() || isLoad()) {
            officeSet = getReason(this.office);
        }
        return officeSet;
    }
    public void setofficeSet(Set<Enumeration> officeSet) {
        this.officeSet = officeSet;
        if (!isWrite()) {
            this.office = toConvertReason(this.officeSet);
        }
    }

    @Column(name = "design_software", length = 4000)
    @Comment("设计软件")
    private String designSoftware; //设计软件
    public void setDesignSoftware(String designSoftware) {

    }

    @Transient
    private Set<Enumeration> designSoftwareSet;

    public Set<Enumeration> getdesignSoftwareSet() {
        if (isWrite() || isLoad()) {
            designSoftwareSet = getReason(this.designSoftware);
        }
        return designSoftwareSet;
    }
    public void setdesignSoftwareSet(Set<Enumeration> designSoftwareSet) {
        this.designSoftwareSet = designSoftwareSet;
        if (!isWrite()) {
            this.designSoftware = toConvertReason(this.designSoftwareSet);
        }
    }
    @Column(name = "programming_language", length = 4000)
    @Comment("编程语言")
    private String programmingLanguage;  //编程语言

    public void setProgrammingLanguage(String programmingLanguage) {
    }

    @Transient
    private Set<Enumeration> programmingLanguageSet;

    public Set<Enumeration> getprogrammingLanguageSet() {
        if (isWrite() || isLoad()) {
            programmingLanguageSet = getReason(this.programmingLanguage);
        }
        return programmingLanguageSet;
    }
    public void setprogrammingLanguageSet(Set<Enumeration> programmingLanguageSet) {
        this.programmingLanguageSet = programmingLanguageSet;
        if (!isWrite()) {
            this.programmingLanguage = toConvertReason(this.programmingLanguageSet);
        }
    }
    @Column(name = "familiar_database", length = 4000)
    @Comment("熟悉的数据库")
    private String familiarDatabase;  //熟悉的数据库

    public void setFamiliarDatabase(String familiarDatabase){
    }

    @Transient
    private Set<Enumeration> familiarDatabaseSet;

    public Set<Enumeration> getfamiliarDatabaseSet() {
        if (isWrite() || isLoad()) {
            familiarDatabaseSet = getReason(this.familiarDatabase);
        }
        return familiarDatabaseSet;
    }
    public void setfamiliarDatabaseSet(Set<Enumeration> familiarDatabaseSet) {
        this.familiarDatabaseSet = familiarDatabaseSet;
        if (!isWrite()) {
            this.familiarDatabase = toConvertReason(this.familiarDatabaseSet);
        }
    }
    @Column(name = "axure", length = 4000)
    @Comment("原型软件")
    private String axure;  //原型软件


    public void setAxure(String axure) {
    }

    @Transient
    private Set<Enumeration> axureSet;

    public Set<Enumeration> getaxureSet() {
        if (isWrite() || isLoad()) {
            axureSet = getReason(this.axure);
        }
        return axureSet;
    }
    public void setaxureSet(Set<Enumeration> axureSet) {
        this.axureSet = axureSet;
        if (!isWrite()) {
            this.axure = toConvertReason(this.axureSet);
        }
    }
    @Column(name = "test_tool", length = 4000)
    @Comment("测试工具")
    private String testTool;  //测试工具

    public void setTestTool(String testTool) {

    }

    @Transient
    private Set<Enumeration> testToolSet;

    public Set<Enumeration> gettestToolSet() {
        if (isWrite() || isLoad()) {
            testToolSet = getReason(this.testTool);
        }
        return testToolSet;
    }
    public void settestToolSet(Set<Enumeration> testToolSet) {
        this.testToolSet = testToolSet;
        if (!isWrite()) {
            this.testTool = toConvertReason(this.testToolSet);
        }
    }
    @Transient
    private Set<Enumeration> getReason(String source) {
        if (StringUtil.isEmpty(source)) return null;
        Set<Enumeration> persons = new HashSet<>();
        String[] rows = source.split(";");
        for (String person : rows) {
            if (person.contains("|")) {
                persons.add(SpringManager.getBean(EnumerationRepository.class).findOne(StringUtils.split(person, "|")[0]));
            }
        }
        return persons;
    }

    private String toConvertReason(Set<Enumeration> persons) {
        StringBuffer sb = new StringBuffer();
        if (!CollectionUtils.isEmpty(persons)) {
            for (Enumeration enumeration : persons) {
                if (sb.length() > 0) {
                    sb.append(";");
                }
                sb.append(enumeration.getId());
                sb.append("|");
                sb.append(enumeration.getDescription());  // 格式 id|description;
            }
        }
        return sb.toString();
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="echelon_type",referencedColumnName = "id")
    @Comment("梯队类型")
    private Enumeration echelonType; //梯队类型

    @Column(name = "lecturer", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否兼职讲师")
    private boolean lecturer = false; //是否兼职讲师(0:否;1:是)

    @Column(name = "coin_spray", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("钣喷员工是否上传职业病因素体检报告")
    private boolean coinSpray = false; //钣喷员工是否上传职业病因素体检报告(0:否;1:是)

    @Column(name = "for_driving", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否在公司备案许可驾驶")
    private boolean forDriving=false; //是否在公司备案许可驾驶（0：否；1：是）

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "transfer_branch_date")
    @Comment("调至本部门时间")
    private Date transferBranchDate;//调至本部门时间

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "transfer_post_date")
    @Comment("调至本岗位时间")
    private Date transferPostDate;//调至本岗位时间

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "transfer_branch_and_post_date")
    @Comment("调至本部门本岗位时间")
    private Date transferBranchAndPostDate;//调至本部门本岗位时间

    @Column(name = "work_handover_focus", nullable = true, length = 200)
    @Comment("工作交接重点")
    private String workHandoverFocus; //工作交接重点

    //
    @Column(name = "age",length = 3)
    @Comment("年龄")
    private Integer age =0; //年龄


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fertility", referencedColumnName = "id")
    @Comment("是否生育")
    private Enumeration fertility ;//生育状况

    @Column(name = "contact_relation", length = 200)
    @Comment("和紧急联系人关系")
    private String contactRelation;  //和紧急联系人关系

    @Column(name = "title", length = 200)
    @Comment("职称")
    private String title;  //从业资格证、职称

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "function", referencedColumnName = "id")
    @Comment("常用函数")
    private Enumeration function;  //常用函数

    @Column(name = "functions")
    @Comment("常用函数")
    private String functions;    //常用函数

    public void setFunctions(String functions) {
    }
    @Transient
    private Set<Enumeration> functionsSet;

    public Set<Enumeration> getFunctionsSet() {
        if (isWrite() || isLoad()) {
            functionsSet = getReason(this.functions);
        }
        return functionsSet;
    }

    public void setFunctionsSet(Set<Enumeration> functionsSet) {
        if(functionsSet == null) return;
        this.functionsSet = functionsSet;
        if (!isWrite()) {
            this.functions = toConvertReason(this.functionsSet);
        }
    }


    @Column(name = "application_job")
    @Comment("应聘职位")
    private String applicationJob;  //应聘职位

    @Column(name = "base_pay", length = 64)
    @Comment("期望底薪")
    private String basePay;  //期望底薪

    @Column(name = "month_income", length = 64)
    @Comment("期望月收入")
    private String monthIncome;  //期望月收入

    @Column(name = "development")
    @Comment("发展规划")
    private String developmentE;  //发展规划

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "availability")
    @Comment("可到岗时间")
    private Date availability;  //可到岗时间

    @Column(name = "live_dormitory", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("需要住员工宿舍")
    private boolean liveDormitory =false;  //需要住员工宿舍

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "recruit_channel_id", referencedColumnName = "id")
    @Comment("招聘渠道")
    private RecruitChannel recruitChannel;  //招聘渠道

    @Column(name = "nature_of_job")
    @Comment("职位性质")
    private String natureOfJob;  //职位性质

    @Column(name = "statement", length = 64)
    @Comment("声明内容")
    private String statement;  //声明内容

    @Column(name = "same_trade_keep_out", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("竞争行业禁止协议")
    private boolean sameTradeKeepOut = false; //是否有签《竞争行业禁止协议》

    @Column(name = "has_other_job", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("是否与其他单位存在劳动关系")
    private boolean hasOtherJob = false;  //是否与其他单位存在劳动关系

    @Column(name = "cognitive_Employee_id")
    @Comment("认识的员工")
    private String cognitiveEmployeeE;   //认识的员工

    @Column(name = "cognitive_relation", length = 16)
    @Comment("与该员工的关系")
    private String cognitiveRelationE;  //与该员工的关系

    @Column(name = "choose_social_security")
    @Comment("购买社保意向")
    private String chooseSocialSecurity;    //购买社保意向

    @Column(name = "unacceptable_id", length = 4000)
    @Comment("不能接受的企业行为")
    private String unacceptables;  //不能接受的企业行为

    public void setUnacceptables(String unacceptables) {
    }

    @Transient
    private Set<Enumeration> unacceptableSet;

    public Set<Enumeration> getunacceptableSet() {
        if (isWrite() || isLoad()) {
            unacceptableSet = getUnacceptable(this.unacceptables);
        }
        return unacceptableSet;
    }

    public void setunacceptableSet(Set<Enumeration> unacceptableSet) {
        this.unacceptableSet = unacceptableSet;
        if (!isWrite()) {
            this.unacceptables = toConvertUnacceptable(this.unacceptableSet);
        }
    }

    @Transient
    private Set<Enumeration> getUnacceptable(String unacceptables) {
        if (StringUtil.isEmpty(unacceptables)) return null;
        Set<Enumeration> persons = new HashSet<>();
        String[] rows = unacceptables.split(";");
        for (String person : rows) {
            if (person.contains("|")) {
                persons.add(SpringManager.getBean(EnumerationRepository.class).findOne(StringUtils.split(person, "|")[0]));
            }
        }
        return persons;
    }

    private String toConvertUnacceptable(Set<Enumeration> unacceptableSet) {
        StringBuffer sb = new StringBuffer();
        for (Enumeration enumeration : unacceptableSet) {
            if (sb.length() > 0) {
                sb.append(";");
            }
            sb.append(enumeration.getId());
            sb.append("|");
            sb.append(enumeration.getDescription());  // 格式 id|description;
        }
        return sb.toString();
    }




}
